<%@ page pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='fxsgl'/></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <form name="totalForm" id="totalForm" class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 80px;"><fmt:message key='yqrmc'/></label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="username" value="${params.username}">
                    </div>
                </div>



                <div class="layui-inline">
                    <button class="layui-btn layui-btn-sm layuiadmin-btn-list" id="search"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> <fmt:message key='ss'/></button>
                </div>

            </div>
        </form>
    </div>
</div>

<div class="layui-card">
    <div class="layui-field-box layui-form">

        <form:form commandName="user" method="PUT">
            <input type="hidden" value="${userId}" name="userId" id="userId">
            <input type="hidden" name="id" id="id">

            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-inline">
                    <input type="button" style="display: none;" value="<fmt:message key='qd1'/>" id="submit" lay-filter="submit" lay-submit class="layui-btn">
                </div>
            </div>
        </form:form>

        <table class="layui-table" lay-size="sm">
            <thead>
            <tr>
                <th width="5%"></th>
                <th><fmt:message key='xh'/></th>
                <th><fmt:message key='yqrmc'/></th>
                <th><fmt:message key='yyxjs'/></th>
            </tr>
            </thead>
            <c:forEach items="${page.result}" var="item" varStatus="status">
                <tr>
                    <td><input type="checkbox" lay-ignore value="${item.id}" class="feijin-check" lay-skin="primary"/></td>
                    <td>${status.index + 1}</td>
                    <td>${item.username}</td>
                    <td>${item.subordinateNum}</td>
                </tr>
            </c:forEach>
        </table>
        <jsp:include page="/commons/page.jsp" flush="true"/>
    </div>
</div>

<script>

    $(function () {
        $("input[type=checkbox]").change(function () {
            if (this.checked) {
                $(this).parent().parent().siblings().find("input[type=checkbox]").prop("checked", false);
            }
        });
    })

    layui.use(['form'], function () {
        var form = layui.form;

        form.on('submit(submit)', function () {

            var id = $("input[type=checkbox]:checked").val();

            if (!id){
                layer.msg("<fmt:message key='qxzyqr'/>");
                return false;
            }

            $("#id").attr("value", id);

            $("#user").ajaxSubmit({
                success: function (res) {
                    if (res.status) {
                        layer.alert("<fmt:message key='xzcg'/>", function () {
                            parent.location.reload();
                        });
                    } else {
                        layer.alert(res.message);
                    }
                }
            });
        });

    });
</script>
</body>
</fmt:bundle>
</html>
